package com.hanthink.system.service.impl.pc;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hanthink.system.mapper.EmTaskItemMapper;
import com.hanthink.common.utils.StringUtils;
import com.hanthink.system.domain.pc.EmTaskItem;
import com.hanthink.system.domain.repair.TaskFile;
import com.hanthink.system.service.pc.IEmTaskItemService;

/**
 * 任务项Service业务层处理
 * 
 * @author hanthink
 * @date 2021-01-22
 */
@Service
public class EmTaskItemServiceImpl implements IEmTaskItemService {
	@Autowired
	private EmTaskItemMapper emTaskItemMapper;

	/**
	 * 查询任务项
	 * 
	 * @param id 任务项ID
	 * @return 任务项
	 */
	@Override
	public EmTaskItem selectEmTaskItemById(Long id) {
		return emTaskItemMapper.selectEmTaskItemById(id);
	}

	@Override
	public List<EmTaskItem> selectEmTaskItemListplus(String taskKey) {
		return emTaskItemMapper.selectEmTaskItemListplus(taskKey);
	}


	@Override
	public List<EmTaskItem> selectEmTaskItemListplus1() {
		return emTaskItemMapper.selectEmTaskItemListplus1();
	}


	/**
	 * 查询任务项列表
	 * 
	 * @param emTaskItem 任务项
	 * @return 任务项
	 */
	@Override
	public List<EmTaskItem> selectEmTaskItemList(EmTaskItem emTaskItem) {
		return emTaskItemMapper.selectEmTaskItemList(emTaskItem);
	}

	/**
	 * 新增任务项
	 * 
	 * @param emTaskItem 任务项
	 * @return 结果
	 */
	@Override
	public int insertEmTaskItem(EmTaskItem emTaskItem) {
		return emTaskItemMapper.insertEmTaskItem(emTaskItem);
	}

	/**
	 * 修改任务项
	 * 
	 * @param emTaskItem 任务项
	 * @return 结果
	 */
	@Override
	public int updateEmTaskItem(EmTaskItem emTaskItem) {
		return emTaskItemMapper.updateEmTaskItem(emTaskItem);
	}

	/**
	 * 批量删除任务项
	 * 
	 * @param ids 需要删除的任务项ID
	 * @return 结果
	 */
	@Override
	public int deleteEmTaskItemByIds(Long[] ids) {
		return emTaskItemMapper.deleteEmTaskItemByIds(ids);
	}

	/**
	 * 删除任务项信息
	 * 
	 * @param id 任务项ID
	 * @return 结果
	 */
	@Override
	public int deleteEmTaskItemById(Long id) {
		return emTaskItemMapper.deleteEmTaskItemById(id);
	}

	@Override
	public List<TaskFile> selectEmTaskItemFileByTask(TaskFile taskFile) {

		List<TaskFile> taskFiles = emTaskItemMapper.selectEmTaskItemFileByTask(taskFile);
		List<TaskFile> resultFiles = new ArrayList<TaskFile>();
		if (taskFiles.size() > 0) {
			for (TaskFile file : taskFiles) {
				if (!StringUtils.isNull(file.getFilePath())) {
					String[] filePaths = file.getFilePath().split(";");
					if (filePaths.length > 0) {
						for (String filePath : filePaths) {
							TaskFile resultFile = new TaskFile();
							resultFile.setFilePath(filePath);
							if (filePath.indexOf(".jpg") != -1) {
								resultFile.setFileType("0");
							} else if (filePath.indexOf(".mp4") != -1) {
								resultFile.setFileType("1");
							} else if (filePath.indexOf(".amr") != -1) {
								resultFile.setFileType("2");
							}
							resultFiles.add(resultFile);
						}

					}
				}
			}
		}
		return resultFiles;
	}
}
